import Vue from 'vue'
import App from './App.vue'
import './styles/base.less'
import './styles/iconfont.css'
import 'lib-flexible'
import moment from 'moment'
import axios from 'axios'
// import 'vant/lib/index.css';
import { Field, Toast, Cell, CellGroup, Dialog, RadioGroup, Radio, Uploader, Button, List } from 'vant';
Vue.use(Field);
Vue.use(Toast);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Dialog);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(Uploader);
Vue.use(Button);
Vue.use(List);


Vue.filter('date', (date, format = 'YYYY-MM-DD') => {
  return moment(date).format(format)
})
// axios.defaults.bassURL = 'http://localhost:3000'
axios.defaults.baseURL = 'http://localhost:3000'
Vue.prototype.$axios = axios
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config;
}, function (error) {

  return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
  const { statusCode, message } = response.data
  if (statusCode == 401 && message == '用户信息验证失败') {
    localStorage.removeItem('token')
    localStorage.removeItem('user_id')
    router.push('/login')
  }
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});
import router from './router/index'
import ShopHeader from './components/ShopHeader.vue'
import ShopLogo from './components/ShopLogo.vue'
import ShopButton from './components/ShopButton.vue'
import ShopStar from './components/ShopStar.vue'
Vue.config.productionTip = false
Vue.component('shop-header', ShopHeader)
Vue.component('shop-logo', ShopLogo)
Vue.component('shop-button', ShopButton)
Vue.component('shop-star', ShopStar)
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
